function h5file = getH5File(ImgSetName, Patch, Aug, batchsize)
% Demo:
%     Patch.scales = 3; % 2:4;
%     Patch.x_size = 41;
%     Patch.y_size = 41;
%     Patch.stride = 41;
%     Patch.batchsize = 64;
%
%     Aug.angles = 1 : 4;
%     Aug.scales = .6 : .1 : .7; % .9;
%     Aug.flip_dims = [1 2];
%
%     Train.files = srdata.getH5File('data291', Patch, Aug);
%     Test.files = srdata.getH5File('Set5', Patch);

if nargin < 3, Aug = []; end

%% search for h5 file
[H5Path, bFound] = srdata.getH5Path(ImgSetName, Patch, Aug);
h5file = fullfile(H5Path, 'dataset.h5');

if bFound && exist(h5file, 'file')
    return
end

%% Augment data
ImgSetPath = srpath.getDataPath(ImgSetName);
if ~isempty(Aug)
    AugPath = fullfile(H5Path, 'Aug');
    ImgSetPath = srimg.augImages(ImgSetPath, Aug, AugPath);
end

%% generate LR and HR image patch pairs
[X, Y] = srimg.genLowHighImgPatchPairs(ImgSetPath, Patch, true);
if ~isempty(Aug) && isdir(ImgSetPath), rmdir(ImgSetPath, 's'); end

%% save to .mat and .h5 file, respectively
% matfile = srdata.FormatFileName(ImgSetName, '', '.mat', Patch.scales, Patch.strides);
% matfile = fullfile(DataPath, matfile);
% save(matfile, 'X', 'Y')
srimg.savemat2h5(h5file, X, Y, batchsize);
